package com.atguigu.spzx.cart.controller;

import com.atguigu.spzx.cart.service.CartService;
import com.atguigu.spzx.model.entity.h5.CartInfo;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "购物车接口管理")
@RestController
@RequestMapping(value="/api/order/cart")
public class CartController {


    @Autowired
    CartService cartService;



    @Operation(summary = "提交订单清除购物车")
    @GetMapping("deleteCartInfoIsCheckedOne")
    public void deleteCartInfoIsCheckedOne(){
        cartService.deleteCartInfoIsCheckedOne();
        return;
    }


    @Operation(summary = "添加购物车接口")
    @GetMapping("/auth/addToCart/{skuId}/{num}")
    public Result addToCart(@PathVariable Long skuId,@PathVariable Integer num){
        cartService.arrToCart(skuId,num);
        return Result.build(num, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "我的购物车查询接口")
    @GetMapping("auth/cartList")
    public Result cartList(){
        List<CartInfo> cartList = cartService.cartList();
        return Result.build(cartList, ResultCodeEnum.SUCCESS);
    }


    @Operation(summary = "删除单个购物车商品")
    @DeleteMapping("auth/deleteCart/{skuId}")
    public Result deleteCart(@PathVariable Long skuId){
        cartService.deleteCart(skuId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "清空购物车")
    @GetMapping("/auth/clearCart")
    public Result clearCart(){
        cartService.clearCart();
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改购物车商品的选中状态")
    @GetMapping("auth/checkCart/{skuId}/{isChecked}")
    public Result checkCart(@PathVariable Long skuId,@PathVariable Integer isChecked){
        cartService.checkCart(skuId,isChecked);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改所有购物车商品的选中状态")
    @GetMapping("auth/allCheckCart/{isChecked}")
    public Result allChecked(@PathVariable Integer isChecked){
        cartService.allChecked(isChecked);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "创建订单页面显示的商品")
    @GetMapping("getCartInfoIsCheckedOne")
    public List<CartInfo> getCartInfoIsCheckedOne(){

        return cartService.getCartInfoIsCheckedOne();
    }
}
